package com.darkplanet.management.controller;

import com.darkplanet.management.domain.Project;
import com.darkplanet.management.service.ProjectService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/ProjectBaseEditUpdateServlet")
public class ProjectBaseEditUpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ProjectService projectService = new ProjectService();
        Integer project_id = (Integer)request.getSession().getAttribute("project_id");

        String project_name = request.getParameter("project_name");
        String client_company = request.getParameter("client_company");
        String customer_principal = request.getParameter("customer_principal");
        String project_manager = request.getParameter("project_manager");
        String developers_num_str = request.getParameter("developers_num");
        int developers_num = Integer.parseInt(developers_num_str);
        String start_time = request.getParameter("start_time");
        String project_time = request.getParameter("project_time");
        String estimated_cost_str = request.getParameter("estimated_cost");
        double estimated_cost = Double.parseDouble(estimated_cost_str);
        String level = request.getParameter("level");
        String finish_time = request.getParameter("finish_time");
        String remark = request.getParameter("remark");
        projectService.updateProject(project_id,project_name,client_company,customer_principal,project_manager,developers_num,start_time,project_time,estimated_cost,level,finish_time,remark);
        request.getRequestDispatcher("/ProjectBaseServlet").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
